<template>
    <div class="centerBox">
        <div class="header">
            <div class="img">
                <img :src="data.img" alt="" />
            </div>
            <div class="text">
                <div class="names">
                    <img :src="boy" class="gender" v-if="data.gender==1" />
                    <img v-else :src="girl" class="gender" />
                    <div class="username">{{ data.username }}</div>
                </div>
                <div class="tag">
                    <span class="tagTitle">个签：</span><span class="tagText">{{ data.tag }}</span>
                </div>
            </div>
        </div>
        <div class="context">
            <div class="item" @click="updateCenter">资料编辑</div>
            <div class="item" @click="loginOut">退出登录</div>
        </div>
        <Dialog v-if="showCenter" @showCenter="updateCenter" @init="Init"></Dialog>
    </div>
</template>
<script lang="ts" setup>
// import { json } from "stream/consumers";
// import { datePickerProps } from "vant";
import { ref, onMounted } from "vue"
import { useRouter } from "vue-router";
import Dialog from "./component/dialog.vue"
const router= useRouter()
const boy = new URL("../../assets/img/boy.png", import.meta.url).href
const girl = new URL("../../assets/img/girl.png", import.meta.url).href
const data = ref({
    img: new URL("../../assets/img/boy.png", import.meta.url).href,
    gender: 0,
    username: "",
    tag: ""
})
const showCenter=ref(false)
const env=import.meta.env.VITE_ENV
const Init=()=>{
    let userInfo=JSON.parse(localStorage.getItem("userInfo")!)
    data.value={...data.value,...userInfo}
    console.log(data.value)
    if(env==='development'){
        data.value.img="http://localhost:9001/static/"+data.value.img
    }else{
        data.value.img="http://49.232.228.40:9001/static/"+data.value.img
    }
}
onMounted(() => {
    Init()
})
const loginOut=()=>{
    localStorage.clear()
    router.replace("/")
}
const updateCenter=()=>{
    showCenter.value=!showCenter.value
}
</script>
<style lang="less" scoped>
.centerBox {
    height: 100vh;
    background-color: #f1f1f1;
    padding: 10px;
    .header {
        // height: 120px;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        background-color: white;
        border-radius: 10px;
        padding: 10px;
        margin-bottom: 10px;
        .img {
            min-width: 60px;
            height: 60px;
            overflow: hidden;
            border-radius: 30px;
            img {
                width: 60px;
            }
        }
        .text {
            max-width: 260px;
            margin-left: 10px;
            border-left: 1px dashed #dad6d6f5;
            padding: 10px;
            display: flex;
            flex-direction: column;
            .names {
                display: flex;
                justify-content: flex-start;
                align-items: flex-end;
                .gender {
                    width: 30px;
                }
                .username {
                    font-size: 14px;
                    font-weight: 600;
                    margin: 5px 5px;
                }
            }
            .tag {
                width: 100%;
                white-space: normal;
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;
                margin-top: 5px;
                .tagTitle {
                    font-size: 13px;
                    white-space:nowrap;
                    color: rgb(114, 113, 110);
                }
                .tagText {
                    word-wrap: break-word;
                    color: rgba(156, 155, 152,0.5);
                }
            }
        }
    }
    .context {
        background-color: white;
        border-radius: 10px;
        padding: 10px;
        .item{
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 10px;
            margin: 5px 0px;
            background-color: rgba(176, 189, 250,0.2);
            border-radius: 10px;
        }

    }
}
</style>
